import { ProTable } from '@ant-design/pro-components';

export default (props: any) => {
    const columns = props.columns.map((item: any) => {
        return {
            ...item,
            hideInSearch: Object.hasOwn(item, 'hideInSearch') ? item.hideInSearch : true,
        };
    });
    return (
        <ProTable
            size="small"
            headerTitle={false}
            bordered={true}
            {...props}
            columns={columns}
            search={columns.some((item: any) => !item.hideInSearch)}
            request={async (params = {}, sort, filter) => {
                const result = await props.request(params, sort, filter);
                return {
                    data: result.data.content,
                    total: result.data.totalElements,
                };
            }}
            pagination={{
                showSizeChanger: true,
                showQuickJumper: true,
                showTotal: (total) => `共 ${total} 条`,
                pageSize: 10
            }}
        />
    );
};
